package com.xxwy.springcloud.controller;

import com.xxwy.springcloud.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author xxwy
 * on 2018/9/29 0029
 */
@RestController
@RequestMapping("consumer")
public class DeptController_Consumer {

    @Autowired
    private RestTemplate restTemplate;

    private static final String REST_URL_PREFIX = "http://XXWYCLOUD-DEPT";

    @PostMapping("dept/add")
    public boolean add(@RequestBody  Dept dept) {
        return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add",dept,Boolean.class);
    }

    @GetMapping("dept/get/{id}")
    public Dept get(@PathVariable("id")Integer id){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/" + id,Dept.class);
    }

    @GetMapping("dept/list")
    public List<Dept> getlist(){
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list" ,List.class);
    }
}
